package huawei.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import huawei.android.widget.DecouplingUtil.ReflectUtil;
import java.lang.reflect.InvocationTargetException;
import o.fkr$d;
import o.fkr$e;
import o.fkr$g;
import o.fkr$i;
import o.fkr.b;
import o.fo;
import o.fqb;
import o.gg;

public class HwEditText extends EditText {
    private static final String ˎ = HwEditText.class.getSimpleName();
    private int ˋ;
    private final Drawable ॱ;

    public HwEditText(Context context) {
        this(context, null);
    }

    public HwEditText(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, fkr$d.ˎ);
    }

    public HwEditText(Context context, AttributeSet attributeSet, int i) {
        super(fqb.ˋ(context), attributeSet, i);
        this.ॱ = fo.ˊ(getContext(), fkr$e.ॱ);
        ॱ(super.getContext(), attributeSet, i);
    }

    private void ॱ(Context context, AttributeSet attributeSet, int i) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, fkr$i.ˊॱ, i, fkr$g.ॱ);
        int color = obtainStyledAttributes.getColor(fkr$i.ᐝॱ, fo.ˋ(context, b.ˊ));
        obtainStyledAttributes.recycle();
        setTextCursorColor(color);
    }

    public void setTextCursorColor(int i) {
        if (i != this.ˋ) {
            this.ˋ = i;
            ˏ();
        }
    }

    private void ˏ() {
        try {
            Class cls = TextView.class;
            Object object = ReflectUtil.getObject(this, "mEditor", cls);
            Class cls2 = Class.forName("android.widget.Editor");
            if (VERSION.SDK_INT >= 28) {
                ReflectUtil.callMethod(object, "updateCursorPosition", null, null, cls2);
                try {
                    Drawable ˊ = ˊ((Drawable) cls.getDeclaredMethod("getTextCursorDrawable", new Class[0]).invoke(this, new Object[0]), this.ˋ);
                    cls.getDeclaredMethod("setTextCursorDrawable", new Class[]{Drawable.class}).invoke(this, new Object[]{ˊ});
                    return;
                } catch (NoSuchMethodException e) {
                    ReflectUtil.setObject("mDrawableForCursor", object, ˊ((Drawable) ReflectUtil.getObject(object, "mDrawableForCursor", cls2), this.ˋ), cls2);
                    return;
                }
            }
            Drawable[] drawableArr = (Drawable[]) ReflectUtil.getObject(object, "mCursorDrawable", cls2);
            if (drawableArr != null) {
                for (int i = 0; i < drawableArr.length; i++) {
                    drawableArr[i] = ˊ(drawableArr[i], this.ˋ);
                }
            }
            ReflectUtil.setObject("mCursorDrawable", object, drawableArr, cls2);
        } catch (IllegalAccessException e2) {
            Log.e(ˎ, "illegal access");
        } catch (InvocationTargetException e3) {
            Log.e(ˎ, "invocation error");
        } catch (ClassNotFoundException e4) {
            Log.e(ˎ, "class not found");
        }
    }

    private Drawable ˊ(Drawable drawable, int i) {
        if (drawable == null) {
            if (this.ˋ == 0 || this.ॱ == null) {
                return null;
            }
            drawable = this.ॱ.mutate();
        }
        Drawable mutate = gg.ʻ(drawable).mutate();
        gg.ॱ(mutate, i);
        return mutate;
    }
}
